import java.io.*;
import java.beans.*;

public class Bank implements VetoableChangeListener, Serializable {

	public static final int AVGCREDIT = 10;

	// should be a vector or something of course
	private Customer ourCustomer;

	public Bank() {
		System.out.println("Bank: Neue Bank erstellt");
	}

	public void vetoableChange(PropertyChangeEvent msg)
			throws PropertyVetoException {
		int amount = ((Integer) msg.getNewValue()).intValue();
		int ownCapital = ((Integer) msg.getOldValue()).intValue();

		if (ourCustomer != null && ownCapital < 5
				&& amount > AVGCREDIT + ownCapital) {
			throw new PropertyVetoException(
					"You do not have that much credit!", msg);
		}
	}

	public void setCustomer(Customer aCustomer) {
		System.out.println("Bank: setCustomer");
		
		ourCustomer = aCustomer;
		if (ourCustomer != null) {
			ourCustomer.addVetoableChangeListener(this);
		}
	}
}
